//Page Object
const url = require('../../config/config.js')
Page({
    data: {

    },
    code: '',
    handleGetUserInfo(e) {
        const { userInfo } = e.detail;
        console.log(userInfo)
        console.log(111);
        if (userInfo != undefined) {
            wx.setStorageSync("userInfo", userInfo);
            wx.login({
                success: (result) => {
                    console.log(result)
                    const { code } = result;
                    wx.setStorageSync("code", code)
                    this.authorized(code);

                }
            });
        } else {
            wx.showToast({
                title: '请授权微信账号',
                icon: 'none'
            });
        }

    },
    authorized(e) {
        console.log(e);

        const header = {
            'content-type': 'application/x-www-form-urlencoded',
            'Cookie': "JSESSIONID=" + wx.getStorageSync("token") //读取cookie
        };
        wx.request({
            url: url.b.auth,
            data: {
                code: e,
                // appid: "wxe39100cf631bbac2",
                // secret: '351db1eb1edb60f0f85e738c9ab4283f'
            },
            header: header,
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                console.log(result)
                const { code } = result.data;


                wx.switchTab({
                    url: '/pages/index/index',
                });

            }
        });

    }
});